﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;
using System.ComponentModel;

namespace SignalLab
{
  public class RecordViewModel : ViewModelBase
  {
    public string RecordName
    {
      get { return _RecordName; }
      set
      {
        if (_RecordName != value)
        {
          _RecordName = value;
          RaisePropertyChanged("RecordName");
        }
      }
    }
    private string _RecordName;

    public bool IsUploading
    {
      get { return App.Manager.IsUploading; }
      set
      {
        if (App.Manager.IsUploading != value)
        {
          App.Manager.IsUploading = value;
          RaisePropertyChangedInUITread("IsUploading");
        }
      }
    }

    public int UploadProgress
    {
      get { return _UploadProgress; }
      set
      {
        if (_UploadProgress != value)
        {
          _UploadProgress = value;
          RaisePropertyChangedInUITread("UploadProgress");
        }
      }
    }
    private int _UploadProgress;


    public RecordViewModel(string recordFile)
      : base()
    {
      _RecordName = recordFile;
    }


    private void RaisePropertyChangedInUITread(string property)
    {
      if (!Deployment.Current.Dispatcher.CheckAccess())
      {
        Deployment.Current.Dispatcher.BeginInvoke(new Action(() => { RaisePropertyChanged(property); }));
        return;
      }
      RaisePropertyChanged(property);
    }
  }
}
